package cn.edu.nwsuaf.examcenter.service.serviceImpl;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import cn.edu.nwsuaf.examcenter.dao.IBaseDao;
import cn.edu.nwsuaf.examcenter.pojo.Manager;
import cn.edu.nwsuaf.examcenter.service.LoginService;

@Service(value="loginService")
public class LoginServiceImpl  extends BaseServiceImpl<Manager> implements LoginService{
	
	@Override
	public String loginManager(Manager manager, HttpSession session,ModelMap modelMap){
		String page;
		Manager target = super.getById(Manager.class, manager.getMno());
		if(target == null){
			modelMap.addAttribute("msg","用户名不存在");
			page="login";
		}else{
			if(target.getMpassword().equals(manager.getMpassword())){
				session.setAttribute("managers", target);
				page = "exam/index";
			}else{
				modelMap.addAttribute("msg","密码错误");
				page="login";
			}
		}
		return page;
	}

	@Override
	public String updateManager(String mno, String mpassword) {
		// TODO Auto-generated method stub
		Manager manager = super.getById(Manager.class, mno);
		manager.setMpassword(mpassword);
		
		super.updateData(manager);
		return "success";
	}
}
